1 package uba.db.sql.interpreter;
2
3 import uba.db.column.CharColumnSpecification;
4 import uba.db.column.ColumnConstraint;
5 import uba.db.column.IntegerColumnSpecification;
6 import uba.db.sql.language.CharColumnDeclaration;
7 import uba.db.sql.language.IntegerColumnDeclaration;
8 import uba.db.sql.language.TableName;
9 import uba.db.sql.language.VisitorBehavior;
10
11 public class CreateTableVisitor extends VisitorBehavior {
12 private CreateTableQueryPlan queryPlan;
13
14 public CreateTableVisitor(CreateTableQueryPlan plan) {
15 queryPlan = plan;
16 }
17
18 public void visitTableName(TableName tableName) {
19 queryPlan.setTableName(tableName.toString());
20 }
21
22 public void visitCharColumnDeclaration(CharColumnDeclaration declaration) {
23 String name = declaration.columnName().nameAsString();
24 boolean constraint = declaration.constraint().notNull();
25 int maxLength = declaration.maxChars();
26 CharColumnSpecification spec = new CharColumnSpecification(name,
27 maxLength, new ColumnConstraint(constraint));
28 queryPlan.addColumnSpecification(spec);
29 }
30
31 public void visitIntegerColumnDeclaration(
32 IntegerColumnDeclaration declaration) {
33 String name = declaration.columnName().nameAsString();
34 boolean constraint = declaration.constraint().notNull();
35 IntegerColumnSpecification spec = new IntegerColumnSpecification(name,
36 new ColumnConstraint(constraint));
37 queryPlan.addColumnSpecification(spec);
38 }
39 }